
$('audio,audio').mediaelementplayer();
$('#playlist').slimScroll({
    position: 'right',
    height: 'inherti',
    color: '#f3f3f3',
                    railVisible: true,
                    alwaysVisible: true
});


$('.itemsong').bind('click',function(){
    $('.itemsong').css('color','white');
    $(this).css('color','#54c5ff');
        var totalTracks=$(".itemsong").length;
        $('#infor-label-filename').html($(this).find(":nth-child(2)").text());
        $('#infor-label-artist').html($(this).attr('data-artist'));  
        if($(this).attr('data-ExtArtist').length==0) {
          $('#space').html('');
        }else {
          $('#space').html('-'); 
        }     
        $('#infor-label-exartist').html($(this).attr('data-ExtArtist'));
        $('#player2').attr("src","<?php echo base_url().'upload/song/';?>"+$(this).attr('path-data'));
        $('#player2').attr("data-current",$(this).attr('data-track'));
        $("#player2").get(0).load();
        $("#player2").get(0).play();
        // if($(this).attr("data-current")*1==totalTracks) {
        //   $('#playlist').scrollTop(elem.offset().top);
        // }
          
        // if($(this).attr("data-current")==1) {
        //   $('#playlist').scrollBottom(elem.offset().top);
        // }
           
});

$("#player2").bind("ended",function() {
  var totalTracks=$(".itemsong").length;
  totalTracks=totalTracks*1;
    currentTrack = $("#player2").attr('data-current');
    newTrack = currentTrack*1+1;
    $('#infor-label-filename').html($("li[data-track='"+newTrack+"']").find(":nth-child(2)").text());
    $('#infor-label-artist').html($("li[data-track='"+newTrack+"']").attr('data-artist'));  
    if($("li[data-track='"+newTrack+"']").attr('data-ExtArtist').length==0) {
      $('#space').html('');
      }else {
        $('#space').html('-');
      }
    if(newTrack <= totalTracks+1) {
     $("#player2").attr("src","<?php echo base_url().'upload/song/';?>"+$("li[data-track='"+newTrack+"']").attr('path-data'));
     $('#player2').attr("data-current",newTrack);
     $("#player2").get(0).load();
     $("#player2").get(0).play();
     $('.itemsong').css('color','white');
   $("li[data-track='"+newTrack+"']").css('color','#54c5ff') ;     
        $('#infor-label-exartist').html($("li[data-track='"+newTrack+"']").attr('data-ExtArtist'));
    } else { return false;}
});


$(".itemsong").hover(function(){
 $(this).children(":first-child").html("<img src='<?php echo $temp_path.'image/icon/itemplay.png'; ?>' width='18px' height='18px'>");
  },function(){
     $(this).children(":first-child") .html($(this).attr("data-track"));
  }
);
$("#viewAll-detail").bind('click',function() {
  if($("#listPlay-info-review").css('height')=='60px') {
    $("#listPlay-info-review").css('height','auto');
    $(this).parent().find("img").attr("src","<?php echo $temp_path.'image/icon/icon11.gif'; ?>");
    $(this).text("Thu gọn");
  } else {
     $("#listPlay-info-review").css('height','60px');
      $(this).parent().find("img").attr("src","<?php echo $temp_path.'image/icon/icon10.gif'; ?>");
       $(this).text("Xem toàn bộ");
  }
});

$(document).ready(function() {
    // put all your jQuery goodness in here.
    $('.itemsong:first').css('color','#54c5ff');
});
